﻿var http = require('http');//引用http模块
var server = http.createServer();//创建http服务器并将该服务器赋值给变量server


var handlers =
  {
    "/":function(req,res){
    console.log(0);
    res.end("func 0");
    //req.on("data",function(d){})
    //res.write //writeHead // res.end("")
},
  "/a":function(req,res){
    console.log(1);
    res.end("func 1");
  },
  "/favicon.ico":function(req,res){
    res.end(); //send file
  }

};


var dispatch=function(req,res) {
    console.log("method:"+req["method"]);
    console.log("url:"+req["url"]);



    if(handlers[req["url"]]){
      handlers[req["url"]](req,res);
    }else{
      res.end("error:404");
    }

};

server.on('request',dispatch);


server.listen(3000, "127.0.0.1");
